package cos.android.tim;

import cos.android.tim.utils.Utils;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageButton;

public class SelectLevel extends Activity implements OnClickListener {

	private ImageButton level1;
	private ImageButton level2;
	private ImageButton level3;
	private ImageButton level4;
	private ImageButton level5;
	private Button back;

	private int world;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.selectlevel);

		Bundle intent = getIntent().getExtras();
		if (intent != null) {
			world = intent.getInt("world");
		}

		level1 = (ImageButton) findViewById(R.id.level1);
		level2 = (ImageButton) findViewById(R.id.level2);
		level3 = (ImageButton) findViewById(R.id.level3);
		level4 = (ImageButton) findViewById(R.id.level4);
		level5 = (ImageButton) findViewById(R.id.level5);
		back = (Button) findViewById(R.id.backButton);

		level1.setOnClickListener(this);
		level2.setOnClickListener(this);
		level3.setOnClickListener(this);
		level4.setOnClickListener(this);
		level5.setOnClickListener(this);
		back.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		Intent i;
		i = new Intent(this, Tim.class);
		i.putExtra("world", world);
		switch (v.getId()) {

		case (R.id.level1):
			i.putExtra("level", 1);
			break;

		case (R.id.level2):
			i.putExtra("level", 2);
			break;

		case (R.id.level3):
			i.putExtra("level", 3);
			break;
		case (R.id.level4):
			i.putExtra("level", 4);
			break;
		case (R.id.level5):
			i.putExtra("level", 5);
			break;
		case (R.id.backButton):
			i = new Intent(this, SelectWorld.class);

		}
		startActivity(i);
		finish();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);

		menu.add(Menu.NONE, Utils.MENU_BACK, Menu.NONE, R.string.backInitStr);
		menu.add(Menu.NONE, Utils.MENU_EXIT, Menu.NONE, R.string.salirStr);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case Utils.MENU_BACK:
			Intent i = new Intent(this, SelectWorld.class);
			startActivity(i);
			finish();
			return true;

		case Utils.MENU_EXIT:
			finish();
			return true;
		}
		return false;
	}
}
